package com.guigu.serviceorder.controller;

import com.guigu.common_util.pojo.utils.Result;
import com.guigu.serviceorder.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("cart")
public class CartController {

    @Autowired
    private CartService cartService;

    @GetMapping("/findCartList")
    public List<Map<String,Object>> findCartList(String username){
        return cartService.findCartList(username);
    }

    @GetMapping("addItem")
    public void addItem(String username,String skuId,Integer num){
        cartService.addItem(username,skuId,num);
    }

    /**
     * 更改购物车项选中状态
     * @param skuId
     * @param checked
     * @return
     */
    @GetMapping("/updateChecked")
    public void updateChecked(String username,String skuId, boolean checked){
        cartService.updateChecked(username,skuId,checked);
    }

    /**
     * 删除选中的购物车
     */
    @GetMapping("/deleteCheckedCart")
    public void deleteCheckedCart(String username){
        cartService.deleteCheckedCart(username);
    }


    /**
     * 计算当前选中的购物车的优惠金额
     * @param
     * @return
     */
    @GetMapping("/preferential")
    public Map preferential(String username){
        int preferential = cartService.preferential(username);
        Map map=new HashMap();
        map.put("preferential",preferential);
        return map;
    }

    @GetMapping("/findNewOrderItemList")
    public List<Map<String,Object>> findNewOrderItemList(String username) {
        return cartService.findNewOrderItemList(username);
    }

}
